package com.work.dao;

import com.work.pojo.Car;
import com.work.pojo.CarInfo;
import com.work.pojo.Goods;
import com.work.utils.DBUtil;

import java.util.List;

public class CarDaoImpl extends DBUtil implements CarDao {

    @Override
    public int insertNewGoodsCar(int goods_num, int goods_id, int user_id) {
        String sql="insert into car values (?,?,?,?)";
        return super.executeUpdate(sql,user_id,goods_num,goods_id,user_id);
    }

    @Override
    public int insertRepeatGoodsCar(int user_id, int goods_id, int goods_num) {
        String sql="UPDATE car SET goods_num=? WHERE cart_id=? AND goods_id=?";
        return super.executeUpdate(sql,goods_num,user_id,goods_id);
    }

    @Override
    public List<CarInfo> queryCarInfo(int user_id) {
        String sql="SELECT goods.`goods_id`,goods.`goods_name`,goods.`goods_price`,car.`goods_num`,goods.`goods_image` FROM user INNER JOIN goods INNER JOIN car ON user.`user_id`=car.`user_id` and goods.`goods_id`=car.`goods_id` WHERE user.`user_id`=?";
        return super.executeQueryList(sql, CarInfo.class,user_id);
    }

    @Override
    public Car IsRepeatGoods(int goods_id,int user_id) {
        String sql ="select * from car where goods_id = ? and user_id = ?";
        return super.executeQueryOne(sql,Car.class,goods_id,user_id);
    }



    @Override
    public Car GoodsNum(int user_id,int goods_id) {
        String sql=" SELECT goods_num FROM car where user_id = ? and goods_id = ?";
        return super.executeQueryOne(sql,Car.class,user_id,goods_id);
    }

    @Override
    public int clearCar(int user_id) {
        String sql="delete from car where user_id = ? ";

        return super.executeUpdate(sql,user_id);
    }

    @Override
    public int deleteGoodsInCarByid(int user_id, int goods_id) {
        String sql="delete from car where user_id=? and goods_id=?";
        return super.executeUpdate(sql,user_id,goods_id);
    }
}
